package logic

import (
	"context"

	"gb28181/gb28181"
	"gb28181/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HeartbeatLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHeartbeatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HeartbeatLogic {
	return &HeartbeatLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HeartbeatLogic) Heartbeat(in *gb28181.DeviceHeartbeatRequest) (*gb28181.DeviceHeartbeatResponse, error) {
	// 更新设备心跳
	l.svcCtx.ClientMgr.UpdateHeartbeat(l.ctx, in.DeviceId)

	l.Debugf("设备心跳更新: %s", in.DeviceId)

	return &gb28181.DeviceHeartbeatResponse{
		Success: true,
		Message: "心跳更新成功",
	}, nil
}
